<?
/**
 * Copyright 2007 Melange.
 *
 * This file is part of PHP-MELANGE.
 *
 * PHP-MELANGE is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * PHP-MELANGE is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with PHP-MELANGE; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 *
 * @category    Melange
 * @package     php-melange
 * @subpackage  cms
 * @copyright   Copyright (c) 2007 Jeroen Simons. All rights reserved
 * @author      Jeroen Simons <jeroen@melange.nl>
 * @link        http://www.melange.nl/
 *
 */
?>
<?=$this->header()?>


    <?=$this->menu("menus")?>


    <h1><?=$this->message("label.header", _Menu::BUNDLE)?></h1>


    <? /* Breadcrums route & page info display */ ?>
    <?=$this->route(
        $this->message("label.header", _Menu::BUNDLE),  // Route display
        $this->menuListForm,                               // ListForm (for page info, see float right)
        $this->menus($this->menuListForm)->getRows()       // The total amount of pages
    )?>

    <? /* Show status messages */ ?>
    <?=$this->messages(_Core::BUNDLE)?>


    <? /* Show error messages */ ?>
    <?=$this->errors(null, _Core::BUNDLE)?>


    <form id="<?=get_class($this->menuListForm)?>"
          method="post"
          action="menu/list"
          onsubmit="return confirmDelete('<?=$this->message("message.confirm.delete", _Core::BUNDLE)?>', this)">


        <? /* Show the Search & Filter Panel */ ?>
        <?=$this->panel(
            "menu/edit",                // Add New URL
            $this->menuListForm,                      // ListForm
            array(                                    // Filter fields
                MenuPeer::NAME=>$this->message("prompt.name", _Menu::BUNDLE),
                MenuPeer::INSERT_DATE=>$this->message("choose.created", _Core::BUNDLE),
                MenuPeer::MODIFIED_DATE=>$this->message("choose.modified", _Core::BUNDLE),
                MenuPeer::ACTIVE=>$this->message("choose.active", _Core::BUNDLE)
            )
        )?>


        <? /* Start output buffering in case there are no results */ ?>
        <?$this->start()?>


        <table cellspacing="0" cellpadding="0" class="list">
        <tr>
            <th class="checkbox"></th>

            <? /* Hide i18n if disabled */ ?>
            <? if($this->param(_Core::I18N)): ?>
                <th class="narrow" title="<?=$this->message("title.language", _Core::BUNDLE)?>">
                    <?=$this->message("label.language", _Core::BUNDLE)?>
                </th>
            <? endif; ?>

            <th>
                <?=$this->TH(
                    $this->menuListForm,                            // ListForm
                    MenuPeer::NAME,                              // Sort Field
                    $this->message("prompt.name", _Menu::BUNDLE) // Header Name
                )?>
            </th>
            <th class="narrow">
                <?=$this->TH(
                    $this->menuListForm,                            // ListForm
                    "count",                                        // Sort Field
                    $this->message("label.items", _Menu::BUNDLE) // Header Name
                )?>
            </th>
            <th class="narrow">
                <?=$this->TH(
                    $this->menuListForm,                           // ListForm
                    MenuPeer::MODIFIED_DATE,                    // Sort Field
                    $this->message("choose.modified", _Core::BUNDLE) // Header Name
                )?>
            </th>
            <th class="narrow">
                <?=$this->TH(
                    $this->menuListForm,                          // ListForm
                    MenuPeer::INSERT_DATE,                     // Sort Field
                    $this->message("choose.created", _Core::BUNDLE) // Header Name
                )?>
            </th>
            <th class="narrow" title="<?=$this->message("title.active", _Core::BUNDLE)?>">
                <?=$this->TH(
                    $this->menuListForm,                        // ListForm
                    MenuPeer::ACTIVE,                        // Sort Field
                    $this->message("label.active", _Core::BUNDLE) // Header Name
                )?>
            </th>
            <th class="buttons"></th>
        </tr>

        <? foreach($this->menus($this->menuListForm)->getItems() as $menu): ?>

            <tr class="ctrl">
                <td class="checkbox">
                    <input type="checkbox"
                           name="items[]"
                           value="<?=$menu->getMenuId()?>"
                           <?=in_array($menu->getMenuId(), $this->menuListForm->getItems()) ? " checked=\"checked\"" : ""?> />
                </td>

                <? /* Hide i18n if disabled */ ?>
                <? if($this->param(_Core::I18N)): ?>
                    <td title="<?=$this->message("title.language", _Core::BUNDLE)?>">

                        <img src="static.php?file=<?=$this->image("cms/core/view/gfx/flag/".strtolower($menu->getLanguage()->getCode()).".png")?>"
                             width="16" height="11" alt="<?=$menu->getLanguage()->getName()?>"
                             title="<?=$menu->getLanguage()->getName()?>" />

                    </td>
                <? endif; ?>

                <td><?=$menu->getName()?></td>
                <td title="<?=$this->message("title.items", _Menu::BUNDLE)?>">
                    <a title="<?=$this->message("title.items", _Menu::BUNDLE)?>" href="menu/item/list?id=<?=$menu->getMenuId()?>&parentId=0">
                        <?=$menu->getCount()?>
                    </a>
                </td>
                <td title="<?=$this->message("title.modified", _Core::BUNDLE)?> <?=$menu->getModifiedDate(_Core::FORMAT_DATETIME)?>">
                    <?=$menu->getModifiedDate(_Core::FORMAT_DATE)?>
                </td>
                <td title="<?=$this->message("title.created", _Core::BUNDLE)?> <?=$menu->getInsertDate(_Core::FORMAT_DATETIME)?>">
                    <?=$menu->getInsertDate(_Core::FORMAT_DATE)?>
                </td>
                <td title="<?=$this->message("title.active", _Core::BUNDLE)?>">
                    <?=$this->message("label." . ($menu->getActive() ? "yes" : "no"), _Core::BUNDLE)?>
                </td>
                <td class="buttons">

                    <input type="button"
                           onclick="to('menu/edit?menu->menuId=<?=$menu->getMenuId()?>')"
                           class="button"
                           value="<?=$this->message("button.edit", _Core::BUNDLE)?>" />
                    <input type="button"
                           onclick="del(<?=$menu->getMenuId()?>, '<?=get_class($this->menuListForm)?>')"
                           class="button"
                           value="<?=$this->message("button.delete", _Core::BUNDLE)?>" />

                </td>
            </tr>

        <? endforeach; ?>

        </table>


        <? /* Edit/Action Bar for checkboxed */ ?>
        <?=$this->edit(
            $this->menuListForm, // ListForm
            array(               // The actions
                "activate"=>$this->message("choose.activate", _Core::BUNDLE),
                "deactivate"=>$this->message("choose.deactivate", _Core::BUNDLE),
                "delete"=>$this->message("choose.delete", _Core::BUNDLE)
            )
        )?>


        <? /* End output buffering */ ?>
        <?$this->end(
            $this->menuListForm,
            "menu/edit",
            $this->menus($this->menuListForm)->getRows()
        )?>


    </form>

<?=$this->footer()?>